﻿using System;
using System.IO;
using System.Text;

namespace Winning.SolutionManager.Util
{
    /// <summary>
    /// 序列化器接口
    /// </summary>
    public interface ISerializer
    {
        /// <summary>
        /// 序列化到流
        /// </summary>
        /// <param name="obj">对象</param>
        /// <param name="stream">流</param>
        /// <param name="encoding">编码</param>
        void Serialize(object obj, Stream stream, Encoding encoding);

        /// <summary>
        /// 序列化到字符串
        /// </summary>
        /// <param name="obj">对象</param>
        string Serialize(object obj);

        /// <summary>
        /// 序列化到文件
        /// </summary>
        /// <param name="obj">对象</param>
        /// <param name="path">文件路径</param>
        /// <param name="encoding">编码</param>
        void Serialize(object obj, string path, Encoding encoding);

        /// <summary>
        /// 反序列化（从流中）
        /// </summary>
        /// <typeparam name="T">对象类型</typeparam>
        /// <param name="stream">流</param>
        /// <param name="encoding">编码</param>
        T Deserialize<T>(Stream stream, Encoding encoding);

        /// <summary>
        /// 反序列化（从字符内容）
        /// </summary>
        /// <typeparam name="T">对象类型</typeparam>
        /// <param name="content">字符内容</param>
        T Deserialize<T>(string content);

        /// <summary>
        /// 反序列化（从文件）
        /// </summary>
        /// <typeparam name="T">对象类型</typeparam>
        /// <param name="path">文件路径</param>
        /// <param name="encoding">文件编码</param>
        T Deserialize<T>(string path, Encoding encoding);
    }
}